package org.example.guavalearn.bloomfilter;

public class CrawlerBuilder {

    private static final long DEFAULT_EXPECTED_INSERTIONS = 1000L;
    private static final double DEFAULT_FPP = 0.01;

    private boolean cache;
    private long expectedInsertions = DEFAULT_EXPECTED_INSERTIONS;
    private double fpp = DEFAULT_FPP;

    public CrawlerBuilder cache(boolean cache) {
        this.cache = cache;
        return this;
    }

    public CrawlerBuilder expectedInsertions(int expectedInsertions) {
        this.expectedInsertions = expectedInsertions;
        return this;
    }

    public CrawlerBuilder expectedInsertions(long expectedInsertions) {
        this.expectedInsertions = expectedInsertions;
        return this;
    }

    public CrawlerBuilder fpp(double fpp) {
        this.fpp = fpp;
        return this;
    }

    public Crawler build() {
        if (cache) {
            fpp = DEFAULT_FPP;
            return new CachedCrawler(new DefaultCrawler(), expectedInsertions, fpp);
        } else {
            return new DefaultCrawler();
        }
    }
}
